<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Add User Information</title>
    <style>
    body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 0;
    }

    h1 {
    text-align: center;
    color: #333;
    }

    form {
    max-width: 600px;
    margin: 20px auto;
    padding: 20px;
    background: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }

    label,
    input,
    select,
    textarea {
    display: block;
    margin-bottom: 15px;
    }

    input,
    select,
    textarea {
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 5px;
    }

    button {
    display: block;
    width: 100%;
    padding: 10px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    }

    button:hover {
    background-color: #45a049;
    }
    </style>


</head>
<body>

<h1>Add Financial Information</h1>
<form action="/mananger/addFinanceMessage" method="post">
    <label for="productName">产品名称</label>
    <input type="text" id="productName" name="productName" required><br>

    <label for="buyBeginDate">购买起始日期:</label>
    <input type="date" id="buyBeginDate" name="buyBeginDate" required><br>

    <label for="buyEndDate">购买终止日期:</label>
    <input type="date" id="buyEndDate" name="buyEndDate" required><br>

    <label for="beginDate">产品起始日期:</label>
    <input type="date" id="beginDate" name="beginDate" required><br>

    <label for="endDate">产品终止日期:</label>
    <input type="date" id="endDate" name="endDate" required><br>

    <label for="timeContinue">期限:</label>
    <input type="text" id="timeContinue" name="timeContinue" required><br>

    <label for="incomeType">收益类型:</label>
    <select id="incomeType" name="incomeType" required>
        <option value="1">业绩基准</option>
        <option value="2">保本理财</option>
        <option value="2">债券</option>
    </select><br>

    <label for="beginMoney">起购金额:</label>
    <input type="text" id="beginMoney" name="beginMoney" required><br>

    <label for="costStatus">销售状态:</label>
    <select id="costStatus" name="costStatus" required>
        <option value="1">已售</option>
        <option value="2">可售</option>
        <option value="2">未售</option>
    </select><br>

    <label for="currencyType">币种:</label>
    <select id="currencyType" name="currencyType" required>
        <option value="1">人民币</option>
        <option value="2">美元</option>
        <option value="2">港币</option>
        <option value="2">欧元</option>
    </select><br>

    <label for="ocType">开封闭类型:</label>
    <select id="ocType" name="ocType" required>
        <option value="1">封闭</option>
        <option value="2">开放</option>
    </select><br>

    <label for="riskType">风险等级:</label>
    <select id="riskType" name="riskType" required>
        <option value="1">低</option>
        <option value="2">中</option>
        <option value="2">高</option>
    </select><br>

    <label for="institution">发行机构:</label>
    <input type="text" id="institution" name="institution" required><br>

    <label for="highRate">最高年利率:</label>
    <input type="text" id="highRate" name="highRate" required>

    <label for="productStatus">产品状态:</label>
    <select id="productStatus" name="productStatus" required>
        <option value="1">正常</option>
        <option value="2">假删除</option>
    </select><br>



    <button type="submit">Submit</button>
</form>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        document.getElementById('userForm').addEventListener('submit', function(event) {
            event.preventDefault();  // 阻止表单默认提交行为

            const formData = new FormData(this);

            fetch('/mananger/addFinanceMessage', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(Object.fromEntries(formData))  // 将 FormData 转换为对象并发送到服务器
            })
                .then(response => response.json())
                .then(result => {
                    if (result.success) {
                        alert("success!")
                        window.location.href = 'addUserMessage.html';  // 重定向到成功页面

                    } else {
                        alert(result.error);  // 显示错误消息
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    alert('Failed to add user information. Please try again.');
                });
        });
    });

</script>

</body>
</html>